/**
 * Author@ Cheng Feitian
 * Date: 2021-3-31
 * Description: 左移运算符重载
 */

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;
const int maxn = 1024;

class Person
{
    friend ostream & operator<<(ostream &cout,Person &p);
public:
    Person(int a,int b){
        m_A = a;
        m_B = b;
    }

private:
    int m_A;
    int m_B;

    //1.通过成员函数重载 左移运算符 p.operator << (cout) 简化版本 p << cout
    //不会利用成员函数重载<< 运算符，因为无法实现cout在左侧
    // void operator<<(Person &p){

    // }
};

//只能利用全局函数重载左移运算符
ostream & operator<<(ostream &cout,Person &p)
{ //本质 operator<< (cout,p) 简化 cout << p
    cout << "m_A = " << p.m_A << endl;
    cout << "m_B = " << p.m_B << endl;
    return cout;
}

void test01()
{
    Person p(10,10);
    // p.m_A = 10;
    // p.m_B = 10;

    // cout << "m_A = " << p.m_A << endl;
    // cout << "m_B = " << p.m_B << endl;
    //重载 <<
    cout << p ;
}

int main()
{
    test01();
    return 0;
}
